package com.company.笔试.xml生成器;

/**
 * 循环队列
 */
public class MyQueue {
    /**
     * 初始化大小
     */
    private final int SIZE = 20;

    /**
     * 数据
     */
    private Object[] queArray;

    /**
     * 队头
     */
    private int front;

    /**
     * 队尾
     */
    private int rear;

    public MyQueue(){
        queArray = new Object[SIZE];
        front = 0;
        rear = -1;
    }

    /**
     * 入队
     * @param o
     */
    public void insert(Object o){
        if (rear == SIZE - 1){
            rear = -1;
        }
        queArray[++rear] = o;
    }

    /**
     * 出队
     * @return
     */
    public Object remove(){
        Object temp = queArray[front++];
        if (front == SIZE){
            front = 0;
        }
        return temp;
    }

    /**
     * 判空
     * @return
     */
    public boolean isEmpty(){
        return (rear + 1 == front || front + SIZE - 1 == rear);
    }
}
